package com.example.hxpc.guidancemanagement.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

import com.example.hxpc.guidancemanagement.R;

/**
 * Created by tao on 2017/12/5.
 */

public class CreatProjectActivity extends Activity implements View.OnClickListener {
    private TextView te_title;
    private ImageView img_add , img_back;
    private Button bu_reset,bu_sure;
    private EditText edt_pro_name , edt_pro_num , edt_pro_teacher;
    private Spinner spinner;
    private String state;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.creat_project);
        initView();
    }

    //初始化组件
    public void initView(){
        te_title = (TextView) findViewById(R.id.te_title);
        te_title.setText("创建项目");
        img_add = (ImageView) findViewById(R.id.add_mark);
        img_add.setVisibility(View.GONE);
        img_back = (ImageView) findViewById(R.id.back);
        img_back.setOnClickListener(this);
        bu_reset = (Button) findViewById(R.id.reset);
        bu_reset.setOnClickListener(this);
        bu_sure = (Button) findViewById(R.id.ok);
        bu_sure.setOnClickListener(this);
        edt_pro_name = (EditText) findViewById(R.id.edit_pro_name);
        edt_pro_num = (EditText) findViewById(R.id.edit_pro_number);
        edt_pro_teacher = (EditText) findViewById(R.id.edit_pro_teacher);
        spinner = (Spinner) findViewById(R.id.spinner);
//        spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                state = (String) spinner.getSelectedItem();
//            }
//        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
            case R.id.reset:
                edt_pro_name.setText("");
                edt_pro_num.setText("");
                edt_pro_teacher.setText("");
                break;
            case R.id.ok:
                Intent intent = new Intent();
                intent.putExtra("name",edt_pro_name.getText().toString());
                intent.putExtra("number",edt_pro_num.getText().toString());
                intent.putExtra("teacher",edt_pro_teacher.getText().toString());
                intent.putExtra("state",spinner.getSelectedItem().toString());
                setResult(1,intent);
                finish();
                break;
        }
    }
}
